<%@ Page Language="C#" Trace="False" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="MasterBacklog.aspx.cs" Inherits="MasterBacklog" Title="Tackle - Master Backlog" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentHolder" runat="Server">
    <span style="font-family: Verdana"><span style="font-size: 10pt"><strong>Master Backlog<br />
        <br />
    </strong><span style="font-size: 8pt">This page contains the intertwined products in
        a single backlog ready for prioritization.<br />
        &nbsp;<br />
        <asp:UpdatePanel runat="server" ID="UPGridView" UpdateMode="Always">
            <ContentTemplate>
                <table cellpadding="4" cellspacing="0" style="width: 98%">
                    <tr>
                        <td bgcolor="#e3eaeb" style="border-top: silver 1px ridge; border-left: silver 1px ridge;
                            border-bottom: silver 1px ridge; border-right-width: 1px; border-right-color: silver;"
                            valign="top" colspan="2" width="130">
                            <span style="font-size: 10pt"><span style="font-size: x-small">Page size:</span><strong>
                            </strong></span>
                            <asp:DropDownList ID="dlPageSize" runat="server" AutoPostBack="True" Font-Names="Verdana"
                                Font-Size="X-Small" OnSelectedIndexChanged="dlPageSize_SelectedIndexChanged">
                                <asp:ListItem>10</asp:ListItem>
                                <asp:ListItem>25</asp:ListItem>
                                <asp:ListItem>50</asp:ListItem>
                                <asp:ListItem>100</asp:ListItem>
                                <asp:ListItem>All</asp:ListItem>
                            </asp:DropDownList></td>
                        <td bgcolor="#e3eaeb" colspan="1" style="border-right: silver 1px ridge; border-top: silver 1px ridge;
                            border-left-width: 1px; border-left-color: silver; border-bottom: silver 1px ridge;
                            text-align: right" valign="top">
                            <span style="font-size: x-small">
                                <asp:CheckBox ID="chbCalcSprint" runat="server" AutoPostBack="True" Checked="True"
                                    OnCheckedChanged="chbCalcSprint_CheckedChanged" Text="Calculate Sprint End" ToolTip="Show or hide the sprint when a feature should be completed" />
                                |
                                <asp:CheckBox ID="chbRankShowDD" runat="server" AutoPostBack="True" Font-Names="Verdana"
                                    Font-Size="X-Small" Text="Show Rank Drop List" ToolTip="Show or hide the Rank Sort drop down list" OnCheckedChanged="chbRankShowDD_CheckedChanged" />
                                | Move Selected Items to Rank </span>
                            <asp:DropDownList ID="ddChangeRank" runat="server" DataSourceID="dsBacklogEntry" DataTextField="MasterRank"
                                DataValueField="MasterRank" Font-Names="Verdana" Font-Size="X-Small">
                            </asp:DropDownList>
                            <asp:Button ID="btnUpdateRank" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                OnClick="btnUpdateRank_Click" Text="Go" />
                    </tr>
                    <tr>
                        <td colspan="3">
                            <asp:GridView ID="gvBacklog" runat="server" AllowPaging="True" AllowSorting="True"
                                AutoGenerateColumns="False" CellPadding="4" DataSourceID="dsBacklogEntry" Font-Names="Verdana"
                                Font-Size="X-Small" ForeColor="#333333" GridLines="Horizontal" OnPreRender="gvBacklog_PreRender"
                                DataKeyNames="MasterBacklogID" Width="100%" OnRowDeleting="gvBacklog_RowDeleting" OnRowDataBound="gvBacklog_RowDataBound">
                                <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                <RowStyle BackColor="#E3EAEB" VerticalAlign="Top" />
                                <EditRowStyle BackColor="#7C6F57" VerticalAlign="Top" />
                                <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                                <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                                <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                <AlternatingRowStyle BackColor="White" />
                                <Columns>
                                    <asp:BoundField DataField="MasterBacklogID" HeaderText="ID" InsertVisible="False"
                                        ReadOnly="True" SortExpression="MasterBacklogID" />
                                    <asp:BoundField DataField="ProductName" HeaderText="Product" ReadOnly="True" SortExpression="ProductName" />
                                    <asp:BoundField DataField="ReleaseDate" DataFormatString="{0:d}" HeaderText="RTX"
                                        HtmlEncode="False" ReadOnly="True" SortExpression="ReleaseDate" Visible="False" />
                                    <asp:TemplateField HeaderText="Feature" SortExpression="Feature">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox1" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                Text='<%# Bind("Feature") %>' Height="36px" TextMode="MultiLine" Width="98%"></asp:TextBox><br />
                                            <asp:RequiredFieldValidator
                                                    ID="rfv1" runat="server" ControlToValidate="TextBox1" ErrorMessage="*?" ForeColor="LightCoral"
                                                    Font-Names="Verdana" Font-Size="Small" ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator><asp:CustomValidator
                                                    ID="cvalidFeature" runat="server" ControlToValidate="TextBox1" ErrorMessage="* 255 max."
                                                    ForeColor="LightCoral" OnServerValidate="CustValMLMaxLength_ServerValidate" ToolTip="255"></asp:CustomValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Feature") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Activity" SortExpression="Activity">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox2" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                Text='<%# Bind("Activity") %>' Width="90px"></asp:TextBox><asp:RequiredFieldValidator
                                                    ID="rfv2" runat="server" ControlToValidate="TextBox2" ErrorMessage="*?" ForeColor="LightCoral"
                                                    Font-Names="Verdana" Font-Size="Small" ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("Activity") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Description" SortExpression="Description">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox3" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                Text='<%# Bind("Description") %>' Height="36px" TextMode="MultiLine" Width="98%"></asp:TextBox><asp:RequiredFieldValidator
                                                    ID="rfv3" runat="server" ControlToValidate="TextBox3" ErrorMessage="*?" ForeColor="LightCoral"
                                                    Font-Names="Verdana" Font-Size="Small" ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator><asp:CustomValidator
                                                        ID="cvalidDesc" runat="server" ControlToValidate="TextBox3" ErrorMessage="* 2048 max."
                                                        ForeColor="LightCoral" OnServerValidate="CustValMLMaxLength_ServerValidate" ToolTip="2048"></asp:CustomValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblDescription" runat="server" Text='<%# Bind("Description") %>' OnPreRender="lblDescription_PreRender"></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Product Priority" SortExpression="ProductPriority"
                                        Visible="False">
                                        <EditItemTemplate>
                                            <asp:Label ID="Label3" runat="server" Text='<%# Eval("ProductPriority") %>'></asp:Label>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label3" runat="server" Text='<%# Eval("ProductPriority") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Product Rank" SortExpression="ProductRank" Visible="False">
                                        <EditItemTemplate>
                                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("ProductRank") %>'></asp:Label>
                                        </EditItemTemplate>
                                        <HeaderStyle Wrap="False" />
                                        <ItemTemplate>
                                            <asp:Label ID="Label4" runat="server" Text='<%# Eval("ProductRank") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Master Rank" SortExpression="MasterRank">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox5" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                Text='<%# Bind("MasterRank", "{0:F}") %>' Width="35px" OnPreRender="SetupOnFocus_PreRender"></asp:TextBox><asp:RequiredFieldValidator
                                                    ID="rfv5" runat="server" ControlToValidate="TextBox5" ErrorMessage="*?" ForeColor="LightCoral"
                                                    Font-Names="Verdana" Font-Size="Small" ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator><asp:RangeValidator
                                                        ID="rv5" runat="server" ControlToValidate="TextBox5" ErrorMessage="*#" ForeColor="LightCoral"
                                                        Font-Names="Verdana" Font-Size="Small" MaximumValue="10000" MinimumValue="0"
                                                        ToolTip="This field must contain a number between 0 and 10000" Type="Double"></asp:RangeValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chbRank" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                Text='<%# Eval("MasterRank", "{0:F}") %>' Visible='<%# (!(bool)Eval("ShowDropDown")) %>' /><asp:DropDownList
                                                    ID="ddRankSort" runat="server" AutoPostBack="True" DataSourceID="dsMasterRankList"
                                                    DataTextField="MasterRank" DataValueField="MasterRank" Font-Names="Verdana"
                                                    Font-Size="X-Small" OnSelectedIndexChanged="ddRankSort_SelectedIndexChanged"
                                                    SelectedValue='<%# Bind("MasterRank") %>' Visible='<%# Eval("ShowDropDown") %>'> 
                                                </asp:DropDownList><asp:Label ID="lblMBID" runat="server" Text='<%# Eval("MasterBacklogID") %>'
                                                    Visible="False"></asp:Label>
                                        </ItemTemplate>
                                        <HeaderStyle Wrap="False" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Estimation" SortExpression="Estimation">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox6" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                Text='<%# Bind("Estimation", "{0:F}") %>' Width="35px" OnPreRender="SetupOnFocus_PreRender"></asp:TextBox><asp:RequiredFieldValidator
                                                    ID="rfv6" runat="server" ControlToValidate="TextBox6" ErrorMessage="*?" ForeColor="LightCoral"
                                                    Font-Names="Verdana" Font-Size="Small" ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator><asp:RangeValidator
                                                        ID="rv6" runat="server" ControlToValidate="TextBox6" ErrorMessage="*#" ForeColor="LightCoral"
                                                        Font-Names="Verdana" Font-Size="Small" MaximumValue="10000" MinimumValue="0"
                                                        ToolTip="This field must contain a number between 0 and 10000" Type="Double"></asp:RangeValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label6" runat="server" Text='<%# Eval("Estimation", "{0:F}") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Accum. Time" InsertVisible="False">
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Sprint End" InsertVisible="False"></asp:TemplateField>
                                    <asp:CheckBoxField DataField="FeatureComplete" HeaderText="Complete" SortExpression="FeatureComplete"
                                        Visible="False" />
                                    <asp:CommandField ShowEditButton="True" />
                                    <asp:TemplateField ShowHeader="False" Visible="False">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
                                                ForeColor="Black" OnClientClick="return confirm('Are you sure you want to delete this record?');"
                                                Text="Delete" ToolTip="Delete the feature from the Product Backlog"></asp:LinkButton><br />
                                            <asp:LinkButton ID="lbCopy" runat="server" CausesValidation="False" ForeColor="Black"
                                                OnClick="lbCopy_Click" Text="Copy" ToolTip="Make a duplicate entry of this feature"></asp:LinkButton><br />
                                            <asp:LinkButton ID="lbSplit" runat="server" CausesValidation="False" ForeColor="Black"
                                                OnClick="lbSplit_Click" Text="Split" ToolTip="Split the feature, dividing the time in half and creating a new feature"></asp:LinkButton><asp:Label
                                                    ID="lblMBID2" runat="server" Text='<%# Eval("MasterBacklogID") %>' Visible="False"></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: left; border-top: silver 1px ridge; border-left: silver 1px ridge;
                            border-bottom: silver 1px ridge; border-right: silver 1px ridge;"
                            bgcolor="#e3eaeb" colspan="3" valign="middle">
                            <asp:LinkButton ID="lbReNumRank" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                ForeColor="Black" OnClick="lbReNumMasterRank_Click" ToolTip="Clicking this link will re-number the master rank based on the current master rank order">Re-number Master Rank</asp:LinkButton>
                            |
                            <asp:LinkButton ID="lbMasterRankFromProductRank" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                ForeColor="Black" OnClick="lbMasterRankFromProductRank_Click" ToolTip="Clicking this link will re-number the master rank to the value in the product rank field">Update Master Rank From Product Rank</asp:LinkButton>
                            |
                            <asp:LinkButton ID="lbSortFeatureActivity" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                ForeColor="Black" OnClick="lbSortFeatureActivity_Click" ToolTip="Clicking this link will do a sort by Product, Feature and Activity">Sort by Product, Feature and Activity</asp:LinkButton></td>
                    </tr>
                    <tr>
                        <td bgcolor="#eeebec" colspan="3" style="border-top: silver 1px ridge; border-left: silver 1px ridge;
                            border-bottom: silver 1px ridge; text-align: left; border-right: silver 1px ridge;"
                            valign="middle">
                            <asp:CheckBox ID="chbAutoUpdateRank" runat="server" Checked="True" Font-Names="Verdana"
                                Font-Size="X-Small" Text="Auto Master Rank" ToolTip="When this is checked, a change to a master rank using the dropdown list will cause other ranks to be automatically renumbered to ensure unique ranks per feature." AutoPostBack="True" OnCheckedChanged="chbAutoUpdateRank_CheckedChanged" />
                            |
                            <asp:CheckBox ID="chbShowRTX" runat="server"
                                AutoPostBack="True" Font-Names="Verdana" Font-Size="X-Small" OnCheckedChanged="chbShowRTX_CheckedChanged"
                                Text="Show RTX Date" ToolTip="Show or hide the RTX date column" />
                            |
                            <asp:CheckBox ID="chbShowProductPriority" runat="server" AutoPostBack="True" Font-Names="Verdana"
                                Font-Size="X-Small" OnCheckedChanged="chbShowProductPriority_CheckedChanged" Text="Show Product Priority"
                                ToolTip="Show or hide the Product Priority Column" />
                            |
                            <asp:CheckBox ID="chbShowProdRankCol" runat="server" AutoPostBack="True" Font-Names="Verdana"
                                Font-Size="X-Small" OnCheckedChanged="chbShowProdRankCol_CheckedChanged" Text="Show Product Rank"
                                ToolTip="Show or hide the Product Rank Column" />&nbsp;
                            |
                            <asp:CheckBox ID="chbShowExtraEditCtls" runat="server" AutoPostBack="True" Font-Names="Verdana"
                                Font-Size="X-Small" OnCheckedChanged="chbShowExtraEditCtls_CheckedChanged" Text="Show Delete, Copy & Split"
                                ToolTip="Show or hide the delete, copy and split column" />
                            </td>
                    </tr>
                </table>
                <asp:Label ID="lblCantDelete" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                    ForeColor="Red" Text="The backlog entry cannot be deleted as associated sprint backlog items exist"
                    Visible="False"></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>
    </span>
        <asp:SqlDataSource ID="dsBacklogEntry" runat="server" ConnectionString="<%$ ConnectionStrings:TackleConnectionStringMain %>"
            SelectCommand="SELECT tblMasterBacklog.MasterBacklogID, tblProducts.ProductName, tblProducts.ReleaseDate, tblMasterBacklog.Feature, tblMasterBacklog.Activity, tblMasterBacklog.Description, tblMasterBacklog.ProductRank, tblMasterBacklog.MasterRank, tblMasterBacklog.ProductPriority, tblMasterBacklog.Hours * @TimeMult AS Estimation, tblMasterBacklog.FeatureComplete, @ShowDropDown AS ShowDropDown FROM tblMasterBacklog INNER JOIN tblProducts ON tblMasterBacklog.fProductID = tblProducts.ProductID INNER JOIN tblScrumTeam ON tblProducts.fScrumTeamProductListID = tblScrumTeam.ScrumTeamProductListID WHERE (tblMasterBacklog.FeatureComplete = 0) AND (tblScrumTeam.ScrumTeamID = @ScrumTeamID) AND (tblMasterBacklog.ShowInMB = 1) AND (tblProducts.ProductComplete = 0) ORDER BY tblMasterBacklog.MasterRank, tblMasterBacklog.ProductRank, tblMasterBacklog.ProductPriority"
            DeleteCommand="DELETE FROM tblMasterBacklog WHERE (MasterBacklogID = @original_MasterBacklogID)"
            OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE tblMasterBacklog SET Feature = @Feature, Activity = @Activity, Description = @Description, MasterRank = @MasterRank, Hours = @Estimation WHERE (MasterBacklogID = @original_MasterBacklogID)"
            OnUpdating="dsBacklogEntry_Updating">
            <SelectParameters>
                <asp:ControlParameter ControlID="chbRankShowDD" Name="ShowDropDown" PropertyName="Checked" />
                <asp:SessionParameter DefaultValue="2" Name="ScrumTeamID" SessionField="ScrumTeamID" />
                <asp:SessionParameter Name="TimeMult" SessionField="MBTimeMult" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="original_MasterBacklogID" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Feature" />
                <asp:Parameter Name="Activity" />
                <asp:Parameter Name="Description" />
                <asp:Parameter Name="MasterRank" />
                <asp:Parameter Name="Estimation" />
                <asp:Parameter Name="original_MasterBacklogID" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="dsMasterRankList" runat="server" ConnectionString="<%$ ConnectionStrings:TackleConnectionStringMain %>"
            ProviderName="<%$ ConnectionStrings:TackleConnectionStringMain.ProviderName %>"
            SelectCommand="SELECT DISTINCT tblMasterBacklog.MasterRank FROM tblMasterBacklog INNER JOIN tblProducts ON tblMasterBacklog.fProductID = tblProducts.ProductID INNER JOIN tblScrumTeam ON tblProducts.fScrumTeamProductListID = tblScrumTeam.ScrumTeamProductListID WHERE (tblMasterBacklog.ShowInMB = 1) AND (tblScrumTeam.ScrumTeamID = @ScrumTeamID) ORDER BY tblMasterBacklog.MasterRank" CacheDuration="1" CacheExpirationPolicy="Sliding" EnableCaching="True">
            <SelectParameters>
                <asp:SessionParameter Name="ScrumTeamID" SessionField="ScrumTeamID" />
            </SelectParameters>
        </asp:SqlDataSource>
    </span></span>
</asp:Content>
